@extends('backstage.layout.master')
@section('title', '物流配置列表')
@section('content')
    <style>
        .state li {
            list-style: none;
            float: left;
            padding: 0 20px;
            text-align: center;
            height: 40px;
            line-height: 40px;
        }

        .state ul {
            margin: 0;
        }

        .state a {
            font-size: 12px;
        }
        .che a {
            font-weight: bold;
            color: #7c7c7c;
        }
    </style>
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                物流配置列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                物流配置列表
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="alert alert-info">

                    <i class="icon-hand-right"></i>
                    添加物流配置:&nbsp
                    <input type="text" class="width-10" id="express_name"  placeholder="快递名称">
                    <input type="text" class="width-10" id="express_id" placeholder="快递公司代码">
                    <input type="text" id="classifty" class="width-10" placeholder="分类(拼音首字母)">
                    <button class="btn" onclick="addexpress();">添加</button>

                </div>
                <div class="form-group" align="center">
                    <a href="http://www.kuaidi100.com/download/api_kuaidi100_com(20140729).doc" >
                        所支持的快递公司即快递代码
                    </a>
                </div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>物流公司代码</th>
                            <th>物流名称</th>
                            <th>分类</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @if(isset($express))
                            @foreach ($express as $exp)
                                <tr class="">

                                <td>
                                    {{$exp->express_id}}
                                </td>
                                <td>
                                    {{$exp->express_name}}
                                </td>
                                <td>{{$exp->class}}</td>
                                <td class="center" style="padding-top: 15px">
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="red delete" title="删除" onclick="delexpress({{$exp->id}});">
                                            <i class="icon-trash bigger-130" style="cursor: pointer"></i>
                                        </a>
                                    </div>
                                </td>
                                </tr>
                            @endforeach
                        @else
                            <a>暂无物流配置</a>
                        @endif
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $express->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
        });
        function delexpress(id){
            $.ajax({
                url:"/backstage/express/delete",
                type:"post",
                data:{"id":id},
                datatype:"json",
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        location.reload();
                        return;
                    }
                    swal(re.message,'','warning');
                },
                error:function(){
                    swal('系统繁忙，请稍后重试','','warning');
                }

            });
        }

        function addexpress(){
            swal({
                title:"确认添加吗？",
                text:"",
                type:"warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText:"取消",
                closeOnConfirm: false,
                closeOnCancel: true
            },function(){
                var express_name = $("#express_name").val().trim();
                var express_id	 = $("#express_id").val().trim();
                var classifty	 = $("#classifty").val().trim();
                if(express_name==""||express_name==null){
                    swal('请输入快递名称','','warning');
                    return;
                }
                if(express_id==""||express_id==null){
                    swal('请输入快递公司编码','','warning');
                    return;
                }
                if(classifty==""||classifty==null){
                    swal('请输入分类','','warning');
                    return;
                }
                if(classifty.length>1){
                    swal('分类只能填写一个字母','','warning');
                }
                $.ajax({
                    url:"/backstage/express/add",
                    type:"post",
                    data:{"express_name":express_name,"express_id":express_id,"class":classifty},
                    datetype:"json",
                    success:function(re){
                        if(re.state=="M00000"){
                            swal(re.message,'','success');
                            $("#express_name").val("");
                            $("#express_id").val("");
                            $("#classifty").val("");
                            return;
                        }
                        swal(re.message,'','warning');
                    },
                    error:function(){
                        swal('','系统繁忙，请稍后重试','warning');
                    }
                });
            });
        }
    </script>
@stop
